<?php
// +----------------------------------------------------------------------
// |欧阳长空 2018/5/28 学员model
// +----------------------------------------------------------------------

namespace Common\Model;

use Think\Model;

/**
 * 合作商基础模型
 */
class PartnerModel extends Model
{
	//获取合作商返佣金额
	public function getFenyongMoney($tradeid){
		$trade=M("trade")->find($tradeid);
		
		$course=M("course")->find($trade['course_id']);
		
		$Course_level=C("Course_level");
		
		$str="charges_".$Course_level[$course['level']];
		
		$partner=D("Student")->getStudentChannel($trade['uid']);
		
		return $partner[$str]==""?0:$partner[$str];
	}
	//通过wxid获取合作商人员信息
	public function getPartnerByWX($wxid){
		$p=M("partner")->where("wxid='".$wxid."'")->find();
		if($p){
			return $p;
		}else{
			return 0;
		}
	}
	//获取合作商的扫码量
	public function getWxCount($wxid){
		$p=$this->getPartnerByWX($wxid);
		$count=M("student_wx")->where("channelNo='".$p['channelNo']."'")->count();
		if($count>0){
			return $count;
		}else{
			return 0;
		}
	}
	//获取合作商的报名量
	public function getStudentCount(){
		$p=$this->getPartnerByWX($wxid);
		$count=M("student_wx")->where("channelNo='".$p['channelNo']."' and level=2 ")->count();
		if($count>0){
			return $count;
		}else{
			return 0;
		}
	}
	//我的微信用户
	public function WxList($wxid,$page=1,$r=20){
		$p=$this->getPartnerByWX($wxid);
		$list=M("student_wx")->where("channelNo='".$p['channelNo']."'")->page($page,$r)->order("addtime desc")->select();
		return $list;
	}
	//已下单客户
	public function StudentList($wxid,$page=1,$r=20){
		$p=$this->getPartnerByWX($wxid);
		$list=M("student_wx")->where("channelNo='".$p['channelNo']."'  and level=2 ")->page($page,$r)->order("addtime desc")->select();
		$arr="";
		foreach($list as $k =>$v){
			$arr.=$v['id'].",";
		}
		$arr=substr($arr,0,-1);
		$map['a.uid']=array("IN",$arr);
		$map['a.status']=array('gt',0);
		$orderlist=M("trade a")->join("__STUDENT_INFO__ b on a.uid=b.uid ","left")->field("a.*,b.name")->where($map)->page($page,$r)->order("createtime desc")->select();
		return $orderlist;
	}	
}